package com.easy.service.impl;

import com.easy.annotation.LogMethod;
import com.easy.bean.Product;
import com.easy.mapper.ProductDao;
import com.easy.service.ProductService;
import com.easy.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    ProductDao productDao;
    @LogMethod(serviceName = "商品添加",recordParam = true,recordReturn = true)
    @Override
    public Product add(Product product) {
       productDao.add(product);
       Product result=productDao.one(product.getId());
       return result;
    }

    @LogMethod(serviceName = "商品删除",recordParam = true,recordReturn = true)
    @Override
    public int del(Integer id) {
        return productDao.del(id);
    }

    @LogMethod(serviceName = "商品修改",recordParam = true,recordReturn = true)
    @Override
    public Product edit(Product product) {
       productDao.edit(product);
       return productDao.one(product.getId());

    }

    @LogMethod(serviceName = "商品查询",recordParam = true,recordReturn = true)
    @Override
    public List<Product> all(Product product) {
        return productDao.all(product);
    }

    @LogMethod(serviceName = "商品查询",recordParam = true,recordReturn = true)
    @Override
    public Product one(Integer id) {
        return productDao.one(id);

    }

    @LogMethod(serviceName = "分页查询",recordParam = true,recordReturn = true)
    @Override
    public void page(Page page, Product product) {
        int count =productDao.pageCount(product);
        Object data=productDao.page(product,page);

        page.setCount(count);
        page.setData(data);
    }

}
